package com.flower.background.controller;

import com.flower.entity.Catalog;
import com.flower.service.CatalogService;
import java.util.List;
import java.util.Map;

import com.flower.utils.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/catalog")
public class CatalogController {

	@Autowired
	private CatalogService catalogService;

	/** 查询全部方法 */
	@GetMapping("/findAll")
	public List<Map<String,Object>> findAll() {
		return catalogService.findAll();
	}

	/** 多条件分页查询方法 */
	@GetMapping("/findByPage")
	public PageResult findByPage(Catalog catalog, Integer page, Integer rows) {

		try {
			return catalogService.findByPage(catalog, page, rows);
		}catch (Exception ex){
			ex.printStackTrace();
		}
		return null;
	}



	/** 添加方法 */
	@PostMapping("/save")
	public boolean save(@RequestBody Catalog catalog) {
		try {
			catalogService.save(catalog);
			return true;
		}catch (Exception ex){
			ex.printStackTrace();
		}
		return false;
	}

	/** 修改方法 */
	@PostMapping("/update")
	public boolean update(@RequestBody Catalog catalog) {
		try {
			catalogService.update(catalog);
			return true;
		}catch (Exception ex){
			ex.printStackTrace();
		}
		return false;
	}

	/** 删除方法 */
	@GetMapping("/delete")
	public boolean delete(Long[] ids) {
		try {
			catalogService.deleteAll(ids);
			return true;
		}catch (Exception ex){
			ex.printStackTrace();
		}
		return false;
	}

}
